#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.basic.security.oauth2.handler;

import ${package}.common.component.service.RedisService;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Description: 鉴权失败拦截器
 *
 * @author wenxiaopeng
 * @date 2021/04/12 18:51
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Component
public class TokenEndpointHandlerInterceptor extends HandlerInterceptorAdapter {

	@Resource
	private RedisService redisService;

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		if (response.getStatus() == HttpStatus.NON_AUTHORITATIVE_INFORMATION.value()) {
			String status = "1";
			//登录失败设置请求验证码的状态
			String userName = request.getParameter("username");
			//设置过期时间为12小时
			Long expireTime = 60 * 60 * 12L;
			redisService.set(userName, status, expireTime);
			redisService.remove(request.getParameter("token"));
		}
	}

}
